﻿@using TD.Common.Kendo.Mvc5.Grid

@model string

@{
    var isNew = ViewBag.IsNew;
}

@Html.Hidden("Code", Model)

@(Html.Kendo().Grid<TD.CTS.Data.Entities.TrialMaterial>()
    .Init("MaterialsGrid")
    .Editable()
    .Columns(columns =>
    {
        columns.ButtonsCrud();
        columns.Bound(e => e.Name).Width("100%").Title("Наименование материала");
    })
    .DataSource(dataSource => dataSource
       .Ajax()
       .PageSize(20)
       .Model(model =>
       {
           model.Id(e => e.Id);
           model.Field(e => e.TrialCode).DefaultValue(Model);
       })
       .Read(read => read.Action("GetTrialMaterials", "Trials").Data("GetTrialCode"))
       .Create(create => create.Action("AddTrialMaterial", "Trials"))
       .Update(update => update.Action("UpdateTrialMaterial", "Trials"))
       .Destroy(destroy => destroy.Action("DeleteTrialMaterial", "Trials"))
       .Events(events => events.Error("kendo_grid_error_handler"))
    )
    .Events(events => events.Edit("kendo_grid_onrowedit"))
    .AutoBind(!isNew)
)

<script>
    function GetTrialCode() {
        return { TrialCode: $("#Code").val() };
    }

    $(document).ready(function () {
        kendo_grid_init($("#MaterialsGrid"));
    });
</script>
